<!--
 * @Author: xjt
 * @Date: 2021-06-28 16:59:46
 * @LastEditTime: 2021-06-29 20:49:17
 * @Description: 隔离点
 * @LastEditors: xjt
-->
<template>
  <div>
    <div class="primaryTitle">
      <strong>隔离点</strong>
    </div>
    <div class="wrap">
      <div class="wrapItem">
        <div class="left">
          <div class="numberPanel">
            <div class="numberPanelTop">
              <span class="num">{{totalData.hotel_count.value}}</span>
              <span class="unit">个</span>
            </div>
            <div class="numberPanelDown">{{totalData.hotel_count.label}}</div>
          </div>
          <div class="numberPanel">
            <div class="numberPanelTop">
              <span class="num">{{totalData.house_count.value}}</span>
              <span class="unit">个</span>
            </div>
            <div class="numberPanelDown">{{totalData.house_count.label}}</div>
          </div>
        </div>
        <ul class="right">
          <li class="attrs" v-for="data in totalData.category" :key="data.name">
            {{data.label}}
            <mark>{{data.value}}</mark>个
          </li>
        </ul>
      </div>
      <div class="wrapItem rooms" style>
        <div class="left">
          <div class="numberPanel">
            <div class="numberPanelTop">
              <span class="num">{{totalData.canUseRooms || 0}}</span>
              <span class="unit">个</span>
            </div>
            <div class="numberPanelDown">可用房间数</div>
          </div>
        </div>
        <ul>
          <li class="attrs" v-for="data in totalData.belongHotel" :key="data.name">
            {{data.area_name}}
            <mark>{{data.leave_count}}</mark>个
          </li>
        </ul>
      </div>
      <div class="tipsItem">
        <div class="tipsTitle">
          <span>风险提示</span>
        </div>
        <ul>
          <li v-for="(item, index) in totalData.warning" :key="index">
            <div class="datetime">{{item.datetime}}</div>
            <div class="info">{{item.area_name}}待消杀{{item.leave_count}}间</div>
          </li>
        </ul>
        <el-button round type="primary" size="small">更多</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { getHotelTotal, getHotelTotalWarning } from '@/views/wy-home/api'
import dataConst from './const'
import moment from 'moment'
export default {
  mounted () {
    this.init()
  },
  data () {
    return {
      totalData: {
        house_count: {},
        hotel_count: {},
      }
    }
  },
  computed: {
    keyInfo () {
      return dataConst['place']
    },
  },
  methods: {
    async init () {
      const resp = await getHotelTotalWarning()
      let datetime = moment().format('YYYY-MM-DD HH:mm:ss')
      this.totalData.warning = resp.data.data.map(item => ({ ...item, datetime }))
      const res = await getHotelTotal()
      const data = res.data.data
      let totalData = { ...this.totalData }
      for (const key in this.keyInfo) {
        switch (key) {
          case 'category':
            totalData[key] = Object.entries(this.keyInfo[key]).map(item => {
              const [name, label] = item
              return { name, label, value: data[name] }
            })
            break;
          case 'total':
            Object.entries(this.keyInfo[key]).forEach(item => {
              const [name, label] = item
              totalData[name] = { label, value: data[name] }
            });
            break;
          default:
            totalData[key] = data[this.keyInfo[key]];
            break;
        }
      }
      totalData.canUseRooms = totalData.belongHotel.reduce((total, item) => (total + item.leave_count), 0)
      this.totalData = totalData
    }
  },
}
</script>

<style lang="scss" scoped>
.wrap {
  color: #fff;
  display: grid;
  grid-template-columns: 6fr 4fr;
  grid-column-gap: 10px;
  grid-row-gap: 10px;
  grid-template-areas:
    "a b"
    "c c";
  mark {
    background-color: unset;
    color: #00eaff;
    font-weight: bold;
    margin: 0 0.25em;
  }
  .wrapItem {
    display: grid;
    grid-template-columns: 1fr 2fr;
    justify-content: center;
    align-items: center;
    .left,
    .right {
      padding: 35px 0;
    }
    .numberPanel + .numberPanel {
      margin-top: 18px;
    }
    .right .attrs {
      font-size: 16px;
      margin-bottom: 16px;
      &:last-child {
        margin-bottom: 0;
      }
    }
  }
}
</style>
